import java.util.Arrays;
import java.util.Scanner;

@SuppressWarnings("hiding")
interface IntegerStack<Integer>{
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 
}
class ArrayIntegerStack implements IntegerStack<Integer>{
	private int size=0;
	private int top=0;
	private Integer[] arr;
	public ArrayIntegerStack(int size){
		this.size=size;
		this.arr=new Integer[size];
	}
	public Integer push(Integer item){
		//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。
		if(item==null||size==top){
			return null;	
		}
		else {
    			arr[top++]=item;
			return item;
		}
 	}
	public Integer pop(){
		//出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
		if(empty()){
		      return null;
		}
		else {
		  	Integer elem=arr[--top];
			return elem;
			
		}
        }
	public Integer peek(){
		//获得栈顶元素，如果为空，则返回null.
		if(empty()){
		      return null;
		}
		else {
			return arr[top-1];
	    }
	}
	public boolean empty(){
		//如果为空返回true
		if(top==0){
		  return true;
		}
		else return false;
	}
	public int size(){
		//返回栈中元素个数
	   return top;
	}
	@Override
	public String toString() {
		return  Arrays.toString(arr);
	}	
	
}

public class ArrayIntegerStack_pta453 {
	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		ArrayIntegerStack arrstack=new ArrayIntegerStack(in.nextInt());
		int m=in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(arrstack.push(in.nextInt()));
		}
		System.out.println(arrstack.peek()+","+arrstack.empty()+","+arrstack.size());
		System.out.println(arrstack);
		int x=in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(arrstack.pop());
		}
		System.out.println(arrstack.peek()+","+arrstack.empty()+","+arrstack.size());
		System.out.println(arrstack);
		in.close();
	}
}
